<template>
  <div class="app-container">
    <el-form :inline="true" ref="ruleForm"  :model="formInline" class="demo-form-inline">
       <el-form-item class="with-pre-select" prop="blackTitle">
          <el-input placeholder="请输入值" v-model="formInline.blackTitle" class="input-with-select" :readonly="!formInline.blackType" @keyup.enter.native="toSearch">
            <el-select v-model="formInline.blackType" slot="prepend" placeholder="全部" @change="handleChange">
               <el-option
                  v-for="item in consts.BLACK_LIST_TYPE"
                  :label="item.label"
                  :key="item.value"
                  :value="item.value"

                ></el-option>
            </el-select>
          </el-input>
      </el-form-item>
       <el-form-item label="黑名单群组" prop="level">
        <el-select v-model="formInline.level" multiple  placeholder="请选择" collapse-tags style="width:200px">
          <el-option
            v-for="item in levelList"
            :label="item.levelName"
            :key="item.levelId"
            :value="item.levelId"
             checked
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="添加人" prop="creator">
        <el-input v-model="formInline.creator" placeholder="请输入添加人" @keyup.enter.native="toSearch"></el-input>
      </el-form-item>
      <el-form-item label="最后调整人" prop="lastUpdater">
        <el-input v-model="formInline.lastUpdater" placeholder="最后调整人" @keyup.enter.native="toSearch"></el-input>
      </el-form-item>
       <el-form-item>
        <el-col>
          <el-form-item prop="time" class="data-item">
              <el-select  v-model="formInline.dateType">
                <el-option label="添加时间" :value="0"></el-option>
                <el-option label="最后调整时间" :value="1"></el-option>
              </el-select>
              <el-date-picker
              class="date-picker-box"
                v-model="formInline.time"
                type="datetimerange"
                align="right"
                unlink-panels
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="yyyy-MM-dd HH:mm:ss"
                :default-time="['00:00:00', '23:59:59']"
                :picker-options="pickerWeekStep" >
              </el-date-picker>
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="toSearch">搜索
      </el-button>
      <el-button @click="selfResetForm('ruleForm')">重置</el-button>
    </el-form>
  </div>

</template>
<script>
import { form, grid, pickerOption } from '@/build';


export default {
  name: 'form-filter',
  mixins: [form, grid, pickerOption],
  props: ['levelList'],
  data() {
    return {
      formInline: {
        time: [
          moment().format('YYYY-MM-DD 00:00:00'),
          moment().format('YYYY-MM-DD 23:59:59'),
        ],
        blackType: '', // 类型
        blackTitle: '', // 值
        level: [], // 群组，可多选
        creator: '', // 添加人
        lastUpdater: '', // 最后调整人
        dateType: 0,
        page: 1,
        size: 20,
      },
    };
  },
  methods: {
    handleChange(val) {
      if (!val) {
        this.formInline.blackTitle = '';
      }
    },
    toSearch() {
      this.$emit('on-filter', this.formInline);
    },
    selfResetForm(formName) {
      this.resetForm(formName);
      this.formInline.dateType = 0;
      this.formInline.blackType = '';
      this.levelList.forEach((item) => {
        this.formInline.level.push(item.levelId);
      });
      this.$emit('on-filter', this.formInline);
    },
  },
  watch: {
    levelList(val) {
      if (val.length > 0) {
        this.formInline.level = [];
        val.forEach((item) => {
          this.formInline.level.push(item.levelId);
        });
      }
    },
  },
  mounted() {
    // window.addEventListener('keyup', (e) => {
    //   const event = e || window.event;
    //   const code = event.keyCode || event.which || event.charCode;
    //   if (code == 13) {
    //     this.toSearch();
    //   }
    // });
  },
};
</script>

<style lang="scss" scoped>
  .with-pre-select {
    .el-input-group__prepend {
      .el-select {
        width: 160px;
      }
    }
  }
/deep/ .data-item .el-select{position: relative; left:5px;}
/deep/ .data-item input.el-input__inner{border-top-right-radius: 0;border-bottom-right-radius: 0;background: #f5f7fa !important;color:#909399;border-right:none;width:130px}
/deep/ .data-item  input.el-input__inner:focus{border-color:#dcdfe6 !important}
/deep/ .data-item div.el-input__inner.el-date-editor{border-top-left-radius: 0 !important;border-bottom-left-radius: 0 !important;}
</style>
